package com.mbc.controller;


import com.mbc.comment.Result;
import com.mbc.dto.CommentSectionDTO;
import com.mbc.service.CommentSectionService;
import com.mbc.vo.CommentSectionVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;

/**
 * <p>
 * 评论区表 前端控制器
 * </p>
 *
 * @author suimeng
 * @since 2024-04-21
 */
@RestController
@RequestMapping("/commentSection")
@Api(tags = "评论区接口")
@CrossOrigin
public class CommentSectionController {

    @Autowired
    private CommentSectionService commentSectionService;

    /**
     * 根据活动id新增评论
     *
     * @param activityId        活动 ID
     * @param userId            用户 ID
     * @param commentSectionDTO 评论部分 DTO
     * @return {@link Result}<{@link Boolean}>
     */
    @PostMapping("/insert/{activityId}/{userId}")
    @ApiOperation("根据活动id新增评论")
    public Result<Boolean> insertComment(@PathVariable Integer activityId, @PathVariable Integer userId,
                                         @RequestBody CommentSectionDTO commentSectionDTO) {
        return Result.success(commentSectionService.insertComment(activityId, userId, commentSectionDTO));
    }

    /**
     * 获取评论区内容
     *
     * @param activityId 活动 ID
     * @param page       页
     * @param size       大小
     * @return {@link Result}<{@link ArrayList}<{@link CommentSectionVO}>>
     */
    @PostMapping("/get/{activityId}")
    @ApiOperation("根据活动id分页查询评论")
    public Result<ArrayList<CommentSectionVO>> getComment(@PathVariable Integer activityId,
                                                          @RequestParam Integer page, @RequestParam Integer size) {
        ArrayList<CommentSectionVO> list = commentSectionService.getComment(activityId,page,size);
        return Result.success(list);
    }
}
